<template>
    <div>
        <div class="crumbs">
            <el-breadcrumb separator="/">
                <el-breadcrumb-item>
                    <i class="el-icon-lx-cascades"></i> 
                </el-breadcrumb-item>
            </el-breadcrumb>
        </div>
        <div class="container">
          <el-button type="primary" @click="handleAddConsumer">添加</el-button>
          <el-input class="search" v-model="searchText" placeholder="请输入成员姓名"></el-input>
          <el-table
                :data="searchedTableData"
                border
                class="table"
                ref="multipleTable"
                header-cell-class-name="table-header"
                @selection-change="handleSelectionChange"
            >
                <el-table-column type="selection" width="55" align="center"></el-table-column>
                <el-table-column prop="ResumeLife_id" label="事件编号" ></el-table-column>
                <el-table-column prop="ResumeCno" label="成员编号"></el-table-column>
                 <el-table-column prop="ResumeCname" label="成员姓名"></el-table-column>
                <el-table-column prop="ResumeTime" label="事件时间"></el-table-column>
				        <el-table-column prop="ResumeLife" label="事件内容"></el-table-column>
                         <el-table-column prop="ResumeHonor" label="生平荣誉"></el-table-column>
                <el-table-column label="操作" width="180" align="center">

                    <template slot-scope="scope">
                        <el-button
                            type="text"
                            icon="el-icon-edit"
                            @click="handleEdit(scope.$index, scope.row)"
                        >编辑</el-button>
                        <el-button
                            type="text"
                            icon="el-icon-delete"
                            class="red"
                            @click="handleDelete( scope.row)"
                        >删除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <div class="pagination">
                <el-pagination
                    background
                    layout="total, prev, pager, next"
                    :current-page="query.pageIndex"
                    :page-size="query.pageSize"
                    :total="pageTotal"
                    @current-change="handlePageChange"
                ></el-pagination>
            </div>
        </div>

        <!-- 编辑弹出框 -->
        <el-dialog title="编辑" :visible.sync="editVisible" width="30%">
            <el-form ref="form" :model="form" label-width="70px">
                <el-form-item label="事件编号">
                    <el-input v-model="partsData.ResumeLife_id"></el-input>
                </el-form-item>
                 <el-form-item label="成员编号">
                    <el-input v-model="partsData.ResumeCno"></el-input>
                </el-form-item>
                 <el-form-item label="成员姓名">
                    <el-input v-model="partsData.ResumeCname"></el-input>
                </el-form-item>
                  <el-form-item label="事件时间">
                    <el-input v-model="partsData.ResumeTime"></el-input>
                </el-form-item>
				<el-form-item label="事件内容">
                    <el-input v-model="partsData.ResumeLife"></el-input>
                </el-form-item>
       <el-form-item label="生平荣誉">
                    <el-input v-model="partsData.ResumeHonor"></el-input>
                </el-form-item>
        </el-form>
            <span slot="footer" class="dialog-footer">
                <el-button @click="editVisible = false">取 消</el-button>
                <el-button type="primary" @click="saveEdit">确 定</el-button>
            </span>
        </el-dialog>
      <!-- 添加弹出框 -->
      <el-dialog title="添加" :visible.sync="addVisible" width="30%">
        <el-form ref="form" :model="form" label-width="70px">
          <el-form-item label="事件编号">
            <el-input v-model="tempresumeData.ResumeLife_id"></el-input>
          </el-form-item>
           <el-form-item label="成员编号">
            <el-input v-model="tempresumeData.ResumeCno"></el-input>
          </el-form-item>
             <el-form-item label="成员姓名">
            <el-input v-model="tempresumeData.ResumeCname"></el-input>
          </el-form-item>
          <el-form-item label="事件时间">
            <el-input v-model="tempresumeData.ResumeTime"></el-input>
          </el-form-item>
          <el-form-item label="事内容件">
            <el-input v-model="tempresumeData.ResumeLife"></el-input>
          </el-form-item>
          <el-form-item label="生平荣誉">
            <el-input v-model="tempresumeData.ResumeHonor"></el-input>
          </el-form-item>
        </el-form>
        <span slot="footer" class="dialog-footer">
                <el-button @click="addVisible = false">取 消</el-button>
                <el-button type="primary" @click="Addconsumer">确 定</el-button>
            </span>
      </el-dialog>
    </div>
</template>

<script>
import { resumedelete,fetchgetresume } from '../../api/index';
import { fetchupdateresume,fetchaddresume } from '../../api/index';
export default {
    name: 'basetable',
    data() {
        return {
            searchText: "",
            tableData: [],
            tempresumeData:{},
            multipleSelection: [],
            partsData: {},
            delList: [],
            query: {},
            editVisible: false,
            addVisible:false,
            pageTotal: 0,
            form: {},
            idx: -1,
            id: -1
        };
    },
    created() {
        this.getData();
    },
    computed: {
      searchedTableData() {
        return this.tableData.filter(item => {
          return Object.keys(item).some(key => {
            console.log(item[key]);
            return String(item[key]).indexOf(this.searchText) > -1;
          });
        });
      }
    },
    methods: {
        getData() {
          fetchgetresume().then(res =>{console.info(res)
            this.tableData=res.data.value
            })
        },
        handleDelete(row) {
          this.tempresumeData = row
          resumedelete(this.tempresumeData).then(res=>{console.info(res)
                console.log(this.tempresumeData)
                console.log(res)
                window.location.reload()
          })
        },
        // 编辑操作
        handleEdit(index, row) {
            this.idx = index;
            this.partsData = row;
            this.editVisible = true;
        },
        // 保存编辑
        saveEdit() {
          this.editVisible = false;
          this.$message.success(`修改第 ${this.idx + 1} 行成功`);
          fetchupdateresume(this.partsData).then(res =>{console.info(res)
            console.log(this.partsData)
            console.log(res)
          })
        },
      //添加函数
      handleAddConsumer(){
        this.addVisible = true;
      },
      Addconsumer() {
        this.addVisible = false;
        this.$message.success(`添加成功`);
        fetchaddresume(this.tempresumeData).then(res =>{console.info(res)
          console.log(this.tempresumeData)
          console.log(res)
          window.location.reload()
        })
      },
        // 分页导航
        handlePageChange(val) {
            this.$set(this.query, 'pageIndex', val);
            this.getData();
        }
    }
};
</script>

<style scoped>
.search {
  width: 200px;
  margin: 5px;
}

.table {
    width: 100%;
    font-size: 10px;
}
.red {
    color: #ff0000;
}
</style>